package com.zzyl.nursing.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzyl.nursing.domain.HealthAssessment;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.mapper.HealthAssessmentMapper;
import com.zzyl.nursing.mapper.MemberReservationMapper;
import com.zzyl.nursing.service.IMemberReservationService;
import com.zzyl.nursing.vo.RecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MemberReservationServiceImpl extends ServiceImpl<MemberReservationMapper, Reservation> implements IMemberReservationService {
    @Autowired
    private MemberReservationMapper memberReservationMapper;

    @Override
    public Integer getCancelledReservationCount(Long userId) {
        long time = System.currentTimeMillis();
        LocalDateTime ldt = LocalDateTimeUtil.of(time);
        LocalDateTime startTime = ldt.toLocalDate().atStartOfDay();
        LocalDateTime endTime = startTime.plusDays(1);
        return memberReservationMapper.getCancelledReservationCount(userId, startTime, endTime);
    }

    @Override
    public RecordVo getReservationCountByTime(Long time) {
        // 获取当前时间
        long now = System.currentTimeMillis();
        LocalDateTime ldt = LocalDateTimeUtil.of(now);
        LocalDateTime startTime = ldt.toLocalDate().atStartOfDay();
        LocalDateTime endTime = startTime.plusDays(1);
        return memberReservationMapper.getReservationCountByTime(time, startTime, endTime);
    }

    @Override
    public void add(Reservation reservation) {
        reservation.setStatus(0);
        this.save(reservation);
    }

    @Override
    public List<Reservation> selectReservationList(Reservation reservation) {
        return memberReservationMapper.selectReservationList(reservation);
    }

    @Override
    public void cancel(Long id) {
        removeById(id);
    }
}
